package cn.edu.hqu.cst.android.uc;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.Timer;
import java.util.TimerTask;

public class UC3 extends Activity {
    Button UC3_b;
    private int currentimagineview=0;
    final int[] imagineviews = new int[]{
            R.drawable.gara1,
            R.drawable.gara2,
            R.drawable.gara3,
            R.drawable.gara4,
            R.drawable.gara5
    };
    final int []names = new int []{
            R.id.gara1,
            R.id.gara2,
            R.id.gara3,
            R.id.gara4,
            R.id.gara5
    };
    ImageView [] views = new ImageView[names.length];
    @SuppressLint("HandlerLeak")
    Handler handler = new Handler(){
        @Override
        public  void handleMessage(Message msg){
            if (msg.what==0X123){
                for (int i=0;i<names.length;i++) {
                    views[i].setImageResource(imagineviews[(i + currentimagineview) % names.length]);
                }
                currentimagineview++;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc3);
        UC3_b=findViewById(R.id.back);
        UC3_b.setOnClickListener(v -> {
            Intent UC3_buttona = new Intent(UC3.this,MainActivity.class);
            startActivity(UC3_buttona);
        });
        for(int i=0;i<names.length;i++){
            views[i]=findViewById(names[i]);
        }
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(0x123);
            }
        },0,135);
    }
}